<?php

namespace C\M;

use C\L\Model;

class User extends Model
{
    protected $primaryKey = 'uid';

    public static function findByMobile($mobile)
    {
        $result = User::findFirst([
        'conditions' => 'mobile = :mobile:',
        'bind'       => compact('mobile'),
        ]);

        return $result;
    }


    public function beforeValidationOnCreate()
    {
        $this->addtime = $this->uptime = time();
        return true;
    }

    public function beforeValidationOnUpdate()
    {
        $this->uptime = time();
        return true;
    }

    public function getMosaicTel()
    {
        $front = substr($this->mobile, 0, 3);
        $end   = substr($this->mobile, -4, 4);
        return $front . '****' . $end;
    }
}
